#coding=utf-8
'''
Created on 2009-11-16

@author: dell
'''
from google.appengine.api import users
from google.appengine.ext import db
from mod.jsonout import JsonOut
from mod.member import Member
from mod.exception import expError
from mod.favorite import Favorite
class HtmlOut(JsonOut):
    '''
    classdocs
    '''


    def get(self):
        '''
        Constructor
        '''
        try:
            
            act = self.request.get("act")
            user = users.get_current_user()
            member = None
            if user:
                member = Member().getMember(user) 
            else:
                raise expError("not login")
            tplval = {"member":member}
                
            if act == "account":
                self.display("account.html",tplval)
            if act == "favorite":
                blogkey = self.request.get("blogid")
                if blogkey == "":
                    raise expError("Blogid is null")
                blog = db.get(blogkey)
                if Favorite().add(member,blog):
                    tplval["opmeg"] = "关注成功！"
                else:
                    tplval["opmeg"] = "您已经关注过此话题！"
                tplval["favnum"] = blog.favoritenum
                self.display("favorite.html",tplval)
                
        except expError ,e:
            
            #self.stateDirt(0,e.value)   
            tplval = {"opmeg":"您还没有登录"}
            self.display("error.html", tplval)  